package com.thread.exe;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TestInterrupted {
	public static void main(String[] args) throws InterruptedException {
		final ExecutorService exe = Executors.newCachedThreadPool();
		Future<?> future = exe.submit(new Runnable() {
			boolean interrupted = false;
			@Override
			public void run(){
				try {
					while(true) {
						try {
							Thread.sleep(1000L);
						} catch (InterruptedException e) {
							interrupted = true;
						}
					}
				} finally {
					if(interrupted)
						Thread.currentThread().interrupt();
				} 
			}
		});
		
		Thread.sleep(1000L);
		future.cancel(true);
	}
}
